home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 4 / Amiga Tools 4.iso / tools / netzwerk / magplip / source / magplip.h < prev    next >
C/C++ Source or Header  |  1996-02-26  |  11KB  |  305 lines

  1. #ifndef __MAGPLIP_H
  2. #define __MAGPLIP_H
  3. /*
  4. ** $VER: magplip.h 1.11 (30 Dec 1995)
  5. **
  6. ** magplip.device - Parallel Line Internet Protocol
  7. **
  8. ** Original code written by Oliver Wagner and Michael Balzer.
  9. **
  10. ** This version has been completely reworked by Marius Gröger,
  11. ** introducing slight protocol changes. The new source is
  12. ** a lot better organized and maintainable.
  13. **
  14. ** Additional changes and code cleanup by Jan Kratochvil and Martin Mares.
  15. ** The new source is significantly faster and yet better maintainable.
  16. **
  17. ** (C) Copyright 1993-1994 Oliver Wagner & Michael Balzer
  18. ** (C) Copyright 1995 Jan Kratochvil & Martin Mares
  19. ** (C) Copyright 1995 Marius Gröger
  20. **     All Rights Reserved
  21. **
  22. ** $HISTORY:
  23. **
  24. ** 30 Dec 1995 : 001.011 :  + single dynamic frame buffer
  25. **                          + added a lot of min/max constants
  26. ** 29 Dec 1995 : 001.010 :  + pb_Startup
  27. **                          + new flag PLIPF_REPLYSS
  28. ** 03 Sep 1995 : 001.009 :  + removed PLIP(F|B)_SIDEA
  29. **                          + hardware addressing fields in PLIPBase
  30. ** 30 Aug 1995 : 001.008 :  support for timer-timed timeout :-)
  31. **                          some pecularities moved to compiler.h
  32. ** 13 Aug 1995 : 001.007 :  code cleanup
  33. ** 29 Jul 1995 : 001.006 :  support for arbitration delay
  34. ** 24 Jul 1995 : 001.005 :  only one delay value in config
  35. **                          some volatile elements in GD
  36. ** 25 Apr 1995 : 001.004 :  #define's FAR
  37. ** 06 Mar 1995 : 001.003 :  added collision delays
  38. ** 04 Mar 1995 : 001.002 :  packet-type now ULONG
  39. ** 18 Feb 1995 : 001.001 :  some SAS/C wrappers, better data base handling
  40. ** 12 Feb 1995 : 001.000 :  reworked original
  41. */
  42.  
  43.    /* system header files */
  44. #ifndef DEVICES_SANA2_H
  45. #include <devices/sana2.h>
  46. #endif
  47. #ifndef EXEC_SEMAPHORES_H
  48. #include <exec/semaphores.h>
  49. #endif
  50. #ifndef EXEC_LISTS_H
  51. #include <exec/lists.h>
  52. #endif
  53. #ifndef EXEC_INTERRUPTS_H
  54. #include <exec/interrupts.h>
  55. #endif
  56. #ifndef EXEC_LIBRARIES_H
  57. #include <exec/libraries.h>
  58. #endif
  59. #ifndef DOS_DOS_H
  60. #include <dos/dos.h>
  61. #endif
  62.  
  63. #ifndef __COMPILER_H
  64. #include "compiler.h"
  65. #endif
  66.  
  67.  
  68. /****************************************************************************/
  69.  
  70.  
  71.    /* memory economy is *everything* :-) */
  72. #define SERVERTASKNAME           pb->pb_DevNode.lib_Node.ln_Name
  73.  
  74.       /* default values */
  75. #define PLIP_DEFMTU              1024
  76. #define PLIP_DEFBPS              100000
  77. #define PLIP_DEFRETRIES          32
  78. #define PLIP_DEFTIMEOUT          (500*1000)
  79. #define PLIP_DEFDELAY            0
  80. #define PLIP_DELAYDIFF           2000
  81. #define PLIP_DEFARBITRATIONDELAY 500
  82.  
  83.       /* minimum values */
  84. #define PLIP_MINPRIORITY         -128
  85. #define PLIP_MINMTU              256
  86. #define PLIP_MINRETRIES          1
  87. #define PLIP_MINCOLLISIONDELAY   0
  88. #define PLIP_MINARBITRATIONDELAY 0
  89. #define PLIP_MINTIMEOUT          500
  90. #define PLIP_MINBPS              1
  91.  
  92.       /* maximum values */
  93. #define PLIP_MAXMTU              (128 * 1024)
  94. #define PLIP_MAXRETRIES          127   /* don't try higher values! */
  95. #define PLIP_MAXPRIORITY         127
  96. #define PLIP_MAXCOLLISIONDELAY   999999
  97. #define PLIP_MAXARBITRATIONDELAY 999999
  98. #define PLIP_MAXTIMEOUT          999999
  99. #define PLIP_MAXBPS              0x7fffffff
  100.  
  101.    /* magPLIPs hardware address: log2(two systems) = 1 */
  102. #define PLIP_ADDRFIELDSIZE       1
  103.  
  104.  
  105. /****************************************************************************/
  106.  
  107.  
  108.    /* this _is_ awful, I know */
  109. #define PKTFRAMESIZE_1           4        /* the sync-field and packet-size */
  110. #define PKTFRAMESIZE_2           6                   /* crc and packet type */
  111.  
  112. struct PLIPFrame {
  113.    USHORT   pf_Sync;
  114.    SHORT    pf_Size;
  115.    USHORT   pf_CRC;
  116.    ULONG    pf_Type;
  117.    /*UBYTE    pf_Data[MTU];*/
  118. };
  119.  
  120.  
  121. #define SYNCBYTE_HEAD   0x42
  122. #define SYNCBYTE_CRC    0x01
  123. #define SYNCBYTE_NOCRC  0x02
  124. #define SYNCWORD_CRC    ((SYNCBYTE_HEAD << 8) | SYNCBYTE_CRC)
  125. #define SYNCWORD_NOCRC  ((SYNCBYTE_HEAD << 8) | SYNCBYTE_NOCRC)
  126.  
  127.  
  128. /****************************************************************************/
  129.  
  130.  
  131. struct TrackRec {
  132.    struct MinNode              tr_Link;
  133.    ULONG                       tr_PacketType;
  134.    struct Sana2PacketTypeStats tr_Sana2PacketTypeStats;
  135. };
  136.  
  137.  
  138. /****************************************************************************/
  139.  
  140.  
  141. typedef BOOL (* ASM BMFunc)(REG(a0) void *, REG(a1) void *, REG(d0) LONG);
  142.  
  143. struct BufferManagement
  144. {
  145.     struct MinNode   bm_Node;
  146.     BMFunc           bm_CopyFromBuffer;
  147.     BMFunc           bm_CopyToBuffer;
  148. };
  149.  
  150.  
  151. /****************************************************************************/
  152.  
  153.  
  154.    /*
  155.    ** sent to the server task after being CreateNewProc()ed
  156.    */
  157. struct ServerStartup
  158. {
  159.    struct Message    ss_Msg;
  160.    struct PLIPBase  *ss_PLIPBase;
  161.    BOOL              ss_Error;
  162.    UBYTE             ss_Pad[2];
  163. };
  164.  
  165.  
  166.  
  167. /****************************************************************************/
  168.  
  169.  
  170. struct PLIPBase
  171. {
  172.    struct Library              pb_DevNode;        /* basic device structure */
  173.    UBYTE                       pb_Unit;         /* unit of 1st OpenDevice() */
  174.    UBYTE                       pb_pad1; /* make the following long alligned */
  175.    BPTR                        pb_SegList;               /* pointer to code */
  176.    struct Library          *   pb_MiscBase,          /* various libs & res. */
  177.                            *   pb_CIAABase,
  178.                            *   pb_UtilityBase,
  179.                            *   pb_TimerBase,
  180.                            *   pb_DOSBase,
  181.                            *   pb_SysBase;
  182.    struct ServerStartup    *   pb_Startup;            /* main server proces */
  183.    struct Process          *   pb_Server;             /* main server proces */
  184.    struct Task             *   pb_Task;         /* used for server shutdown */
  185.    struct Interrupt            pb_Interrupt;          /* for AddICRVector() */
  186.    ULONG                       pb_IntSig;        /* sent from int to server */
  187.    ULONG                       pb_IntSigMask;                  /* for speed */
  188.    ULONG                       pb_ServerStoppedSigMask;     /* for shutdown */
  189.    struct MsgPort          *   pb_ServerPort,       /* for IOReq forwarding */
  190.                            *   pb_TimeoutPort,      /* for timeout handling */
  191.                            *   pb_CollPort;       /* for collision handling */
  192.    struct timerequest          pb_TimeoutReq,       /* for timeout handling */
  193.                                pb_CollReq;        /* for collision handling */
  194.    struct Sana2DeviceStats     pb_DevStats;            /* SANA-2 wants this */
  195.    volatile struct List        pb_ReadList,                  /* the readers */
  196.                                pb_WriteList,                 /* the writers */
  197.                                pb_EventList,              /* event tracking */
  198.                                pb_ReadOrphanList,   /* for spurious packets */
  199.                                pb_TrackList,                  /* track type */
  200.                                pb_BufferManagement;          /* Copy-In/Out */
  201.    struct SignalSemaphore      pb_EventListSem,     /* protection for lists */
  202.                                pb_ReadListSem,
  203.                                pb_WriteListSem,
  204.                                pb_TrackListSem,
  205.                                pb_ReadOrphanListSem,
  206.                                pb_Lock;
  207.    ULONG                       pb_Retries;                 /* config values */
  208.    ULONG                       pb_ReportBPS;
  209.    ULONG                       pb_MTU;
  210.    ULONG                       pb_AllocFlags;
  211.    ULONG                       pb_Timeout;
  212.    LONG                        pb_CollisionDelay;
  213.    LONG                        pb_ArbitrationDelay;
  214.    volatile UBYTE              pb_TimeoutSet;/* if != 0, a timeout occurred */
  215.    volatile UBYTE              pb_Flags;                       /* see below */
  216.    APTR                        pb_OldExceptCode;
  217.    APTR                        pb_OldExceptData;
  218.    ULONG                       pb_OldExcept;
  219.    UBYTE                       pb_HandshakeMask[2],   /* crossed for side-a */
  220.                                pb_HandshakeBit[2];            /* and side-b */
  221.    UBYTE                       pb_SrcAddr[PLIP_ADDRFIELDSIZE];
  222.    UBYTE                       pb_DstAddr[PLIP_ADDRFIELDSIZE];
  223.    struct PLIPFrame        *   pb_Frame;
  224. };
  225.  
  226.    /*
  227.    ** used as index for PLIPBase->pb_HandshakeMask[]/pb_HandshakeBit[]
  228.    */
  229. #define HS_LINE        0   /* as we use compatible plip wireing, our magic */
  230. #define HS_REQUEST     1   /* is to cross the lines transparently by software */
  231.  
  232. #ifdef __SASC
  233.      /*
  234.      ** redirect all shared library bases to our device base.
  235.      */
  236. #  define SysBase      pb->pb_SysBase
  237. #  define DOSBase      pb->pb_DOSBase
  238. #  define TimeBase     pb->pb_TimeBase
  239. #  define UtilityBase  pb->pb_UtilityBase
  240. #  define MiscBase     pb->pb_MiscBase
  241. #  define CIAABase     pb->pb_CIAABase
  242. #  define CiaBase      pb->pb_CIAABase
  243. #  define TimerBase    pb->pb_TimerBase
  244.      /*
  245.      ** This macro declares a local variable which temporary gets
  246.      ** SysBase directly from AbsExecBase.
  247.      */
  248. #  define LOCALSYSBASE struct { void *pb_SysBase; } *pb = (void*)0x4
  249.      /*
  250.      ** Use this macro as argument for all functions which need to
  251.      ** have access to your data base.
  252.      */
  253. #  define BASEPTR      struct PLIPBase *pb
  254. #else
  255. #  error Please define library bases for your compiler
  256. #endif
  257.  
  258.    /*
  259.    ** Values for PLIPBase->pb_Flags
  260.    ** Note that the Flags field is intentionally only 8 bits wide so that
  261.    ** the ASM parts my use the bit functions.
  262.    */
  263. #define PLIPB_EXCLUSIVE       1   /* current opener is exclusive */
  264. #define PLIPB_NOTCONFIGURED   2   /* not configured */
  265. #define PLIPB_OFFLINE         3   /* currently not online (sic!) */
  266. #define PLIPB_SENDCRC         4   /* send with CRC sum */
  267. #define PLIPB_RECEIVING       5   /* set by interrupt */
  268. #define PLIPB_COLLISION       6   /* arbitration detected a collision */
  269. #define PLIPB_SERVERSTOPPED   7   /* set by server while passing away */
  270. #define PLIPB_REPLYSS         8   /* server-startup must be replied */
  271.  
  272. #define PLIPF_EXCLUSIVE       (1<<PLIPB_EXCLUSIVE)
  273. #define PLIPF_NOTCONFIGURED   (1<<PLIPB_NOTCONFIGURED)
  274. #define PLIPF_OFFLINE         (1<<PLIPB_OFFLINE)
  275. #define PLIPF_SENDCRC         (1<<PLIPB_SENDCRC)
  276. #define PLIPF_RECEIVING       (1<<PLIPB_RECEIVING)
  277. #define PLIPF_COLLISION       (1<<PLIPB_COLLISION)
  278. #define PLIPF_SERVERSTOPPED   (1<<PLIPB_SERVERSTOPPED)
  279. #define PLIPF_REPLYSS         (1<<PLIPB_REPLYSS)
  280.  
  281.  
  282. /****************************************************************************/
  283.  
  284.  
  285.    /*
  286.    ** configuration stuff
  287.    */
  288. #define CONFIGFILE "ENV:SANA2/magPLIP.config"
  289.  
  290. #define TEMPLATE "TIMEOUT/K/N,PRIORITY=PRI/K/N,MTU/K/N,BPS/K/N,RETRIES/K/N,SENDCRC/S,CD=COLLISIONDELAY/K/N,AD=ARBITRATIONDELAY/K/N"
  291.  
  292. struct PLIPConfig
  293. {
  294.       ULONG *timeout;
  295.       LONG  *priority;
  296.       LONG  *mtu;
  297.       LONG  *bps;
  298.       LONG  *retries;
  299.       ULONG  sendcrc;
  300.       LONG  *collisiondelay;
  301.       LONG  *arbitrationdelay;
  302. };
  303.  
  304. #endif
  305.